package pit.com.ordermobilesystem.a;

import pit.com.ordermobilesystem.R;
import pit.com.ordermobilesystem.adapter.OrderMobileAdapter;
import pit.com.ordermobilesystem.model.Item;
import pit.com.ordermobilesystem.provider.OrderMobileProvider;
import pit.com.ordermobilesystem.tabhost.TabGroupActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ListAdapter;

public class TitlesActivity extends  FragmentActivity {
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.titlesfragment);
		Cursor data = getContentResolver().query(
				OrderMobileProvider.CATEGORY_CONTENT_URI, null, null, null,
				null);

		ExpandableListView lv = (ExpandableListView)findViewById(R.id.expand_list);
		ListAdapter adapter = lv.getAdapter();

		if (adapter == null) {
			OrderMobileAdapter mobileadapter = new OrderMobileAdapter(data,	this);
			lv.setAdapter(mobileadapter);
		} else {
			OrderMobileAdapter mobileadapter = (OrderMobileAdapter) adapter;
			mobileadapter.changeCursor(data);
			mobileadapter.notifyDataSetChanged();
		}
		
		lv.setOnChildClickListener(new OnChildClickListener() {

			@Override
			public boolean onChildClick(ExpandableListView parent, View v,
					int groupPosition, int childPosition, long id) {
				// TODO Auto-generated method stub
				Item item = (Item) v.getTag();


					// đành chia nhỏ và gửi qua
					Bundle send = new Bundle();
					send.putInt("IdItem", item.getId());
					send.putInt("IdCategory", item.getIdCategory());
					send.putString("Description", item.getDescription());
					send.putString("LinkImage", item.getLinkImage());
					send.putString("NameItem", item.getNameItem());
					send.putDouble("Discount", item.getDiscount());
					send.putDouble("Price", item.getPrice());
					
					Intent previewMessage = new Intent();
					previewMessage.setClass(TitlesActivity.this, DetailsActivity.class);
					previewMessage.putExtras(send);
		            TabGroupActivity parentActivity = (TabGroupActivity)getParent();
		            parentActivity.startChildActivity("DetailsActivity", previewMessage);


				return false;
			}
	});
		
	}
}
